<?php
/*
 * emarket - an website to create your own online-shop.  
 * Copyright (C) 2009  Frédéric Delorme
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * To contact me: frederic.delorme@gmail.com
 * to see some information on te project : http://code.google.col/p/os-emarket/
 *
 */
require_once("framework/webapp.php");
require_once("webapp/helpers/html.helpers.php");
require_once("webapp/helpers/cart.helpers.php");

/**
 * Application is the min class for the web application based on the framework.
 * @author frederic
 * @version 1.0
 */
class Application extends WebApp{
	protected $_connected_user;
	/**
	 * initialize the default page (manager) to be displayed at startup.
	 * @return String containing name of the manager (here: "home")
	 */
	protected function setDefaultManager(){
		return "home";
	}

	
	public function initialize(){
		__debug(__CLASS__."::initialize() - start",__FILE__,__LINE__);
		$this->cart = CartHelpers::get();
		__template_set("cart",$this->cart);
		$this->addEntity('category',
			__query_entities(
				"category",
					$where = array(array('field'=>"parent_id",'comparator'=>"=",'value'=>"0")),
					$order = array(	array('field'=>"parent_id",'comparator'=>"ASC"),
						 			array('field'=>"sortorder",'comparator'=>"ASC")),
					$limit = "")
			);
		__template_set("categories",$this->getEntities("category"));
	}
	
	/**
	 * return instance of the Application Oject.
	 * @return Application instance.
	 */	
	public function getInstance(){
		__debug(__CLASS__."::getInstance() - Get instance of this Web Application component",__FILE__,__LINE__);
		
		if(empty(self::$_instance)){
			self::$_instance = new Application(__param('system','appname'));
		}
		return self::$_instance;
	}
}
?>